import Vue from 'vue'
import Vuex from 'vuex'
import * as api from '../util/api';
import http from '../util/http';
import homeStore from './module/homeStore'
import SearchGood from './module/queryGoodsName'
import userRegister from './module/userRegister'
import getRouter from './module/getRouter'
import capitalAccount from './module/capitalAccount'
import paymentDetails from './module/paymentDetails'
import orderStore from './module/orderStore'
import getNotice from './module/getNotice'
import myAccount from './module/myAccount'
import getPromotion from './module/getPromotion'
import getGood from './module/getGood'
import queryGoodsDetail from './module/queryGoodsDetail'
import goodsCollection from './module/goodsCollection'
import GoodsCar from './module/GoodsCar'
import addCar from './module/addCar'
import statisticOrder from './module/statisticOrder'
import StatisticDelivery from './module/StatisticDelivery'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    beishu:0,//屏幕宽度倍数
    //表格样式
    headerCssObj:{    //改变表格表头的样式
      backgroundColor:'#F5F6F7',
      color:'#555555',
      textAlign:'center',
    },
    cellCssObj:{     //改变表格样式
      textAlign:'left',
    },
    msgheaderCssObj:{
      backgroundColor:'#F5F6F7',
    },
    //以上是对表格的统一样式，引用如下：
    //在el-table标签内加    :header-cell-style="this.$store.state.headerCssObj"    :cell-style="this.$store.state.cellCssObj"
    user:{
      //clientId:sessionStorage.getItem('clientId')||undefined,//客户id
      clientId:'',//客户id
      //clientCompany:sessionStorage.getItem('clientCompany')||undefined,//客户公司
      clientCompany:'',//客户公司
      //clientLevelId:sessionStorage.getItem('clientLevelId')||undefined,//客户等级
      clientLevelId:'',//客户等级
      username:sessionStorage.getItem('username')||undefined,//用户名
      password:'',//密码
      //repositoryId:sessionStorage.getItem('repositoryId')||undefined,//发货仓库id
      repositoryId:'',//发货仓库id
      //deptId:sessionStorage.getItem('deptId')||undefined,//所属部门id
      deptId:'',//所属部门id
      //clientName:sessionStorage.getItem('clientName')||undefined,//客户名称
      clientName:'',//客户名称
      //clientTel:sessionStorage.getItem('clientTel')||undefined,//客户联系电话
      clientTel:'',//客户联系电话
      //createTime:sessionStorage.getItem('createTime')||undefined,//客户创建时间
      createTime:'',//客户创建时间
      //stateId:sessionStorage.getItem('stateId')||undefined,//客户类型
      stateId:'',//客户类型
      //clientAddress:sessionStorage.getItem('clientAddress')||undefined,//客户地址
      clientAddress:'',//客户地址
      token:sessionStorage.getItem('token')||undefined,
    },
    //用户操作信息
    userOperation:{
      content:'',//操作类型
      user:'',//操作人
      operation:'',//操作内容
      createDate:'',//操作时间
    },
    //获取当前时间
    nowTime:{
      time:'',
      date:'',
    },
    //搜索数据
    selectValue:'',
    //消息数据及条数
    messageNavData:[
      {path:'/Main/Message/ServiceMessage',name:'业务消息',num:5},
      {path:'/Main/Message/SystemNotice',name:'系统公告',num:0},
      {path:'/Main/Message/UpgradeAnnouncement',name:'升级公告',num:1},
    ],
  },
  mutations: {
    nowTime(state,data){
      state.nowTime.time = data.time
      state.nowTime.date = data.date
    },
    setUser(state,data){
      state.user.clientId = data.clientId
      state.user.clientCompany = data.clientCompany
      state.user.clientLevelId = data.clientLevelId
      state.user.username = data.username
      state.user.password = data.password
      state.user.repositoryId = data.repositoryId
      state.user.deptId = data.deptId
      state.user.clientName = data.clientName
      state.user.clientTel = data.clientTel
      state.user.createTime = data.createTime
      state.user.stateId = data.stateId
      state.user.clientAddress = data.clientAddress
    }
  },
  actions: {
    userLogin({commit},obj){
      //console.log(obj)
      return http({
        url:api.userLogin,
        method:'post',
        data:obj
      }).then(resp=>{
        console.log(resp)
        sessionStorage.setItem('token',resp.data.token)
        sessionStorage.setItem('clientId',resp.data.data.clientId)
        commit('setUser',resp.data.data)
        console.log(resp.data.data)
        //commit('setUser',resp.data.data)
        return resp.data
      }).catch(err=>{
        console.log(err)
      })
    },
    getTime({commit}){
      let date = new Date();
      let yy = date.getFullYear();
      let mm = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
      let dd = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
      let hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
      let mf = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
      let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
      let time = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      commit('nowTime', {time, date})
    },
    userOperationFun({commit},obj){
      console.log(obj)
      // return http({
      //   url:'',
      //   method: 'post',
      //   data:obj,
      // }).then(resp=>{
      //   console.log(resp)
      // }).catch(err=>{
      //   console.log(err)
      // })
    },
  },
  modules: {
    homeStore,
    SearchGood,
    userRegister,
    getRouter,
    capitalAccount,
    paymentDetails,
    orderStore,
    getNotice,
    myAccount,
    getPromotion,
    getGood,
    queryGoodsDetail,
    goodsCollection,
    GoodsCar,
    addCar,
      statisticOrder,
      StatisticDelivery,
  },
  getters:{
    getUserName(state){
      return state.user.username
    },
    getNowTime(state){
      return state.nowTime.time
    }
  }
})
